const request = require('../../utils/request.js');

Page({
  data: {
    orders: [],
    isModalVisible: false,
    selectedRating: 0,
    content:'',
    selectedOrder: {},
    orderid:'',
    merchantId:'',
    washingMachineId:'',
  },

  onLoad(){
    // this.finorderlist();
  },

  onShow(){
    this.finorderlist();
  },

  // 打开订单详情弹出框s
  viewOrderDetails(e) {
    const order_data = e.currentTarget.dataset.data
    this.setData({
      isModalVisible: true,
      orderid: order_data.id,
      merchantId: order_data.merchantId,
      washingMachineId: order_data.washingMachineId,
    });
  },

  // 关闭订单详情弹出框
  closeModal() {
    this.setData({
      isModalVisible: false,
      content: "",  // 关闭时清空内容
      selectedRating: 0,
    });
  },
  submitReview(){
    const param = {
      orderid: this.data.orderid,
      merchantId: this.data.merchantId,
      washingMachineId: this.data.washingMachineId,
      comments: this.data.content,
      rating: this.data.selectedRating,
    }
    request.post('/index/addreviews',param)
    .then(res =>{
      this.closeModal();
      wx.showToast({ title: res.msg, icon: 'none' });
    })
  },

  // 防止滚动
  preventScroll() {},

  finorderlist(){
    request.post('/index/finxiyiorder')
    .then(res=>{
      this.setData({
        orders: res.data
      });
    })
  },
  onRatingChange(event) {
    this.setData({
      selectedRating: event.detail,  // 更新评分
    });
  },

  // 监听评价内容变化
  onInputChange(event) {
    this.setData({
      content: event.detail.value,  // 更新输入框内容
    });
  },
});
